package com.zxp.mapstruct.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;


public enum LevelEnum {

    able(1, "完美"),
    disable(2, "合格"),
    failed(4, "不及格");

    @Getter @Setter
    private Integer code;

    @Getter @Setter
    private String desc;

    LevelEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static LevelEnum getByCode(Integer code){
        LevelEnum[] values = LevelEnum.values();
        for (LevelEnum businessType : LevelEnum.values()){
            if(businessType.getCode()==code){
                return businessType;
            }
        }
        return null;
    }

    public static LevelEnum getByName(String methodName){
        if(StrUtil.isEmpty(methodName)){
            return null;
        }
        LevelEnum[] values = LevelEnum.values();
        for (LevelEnum businessType : LevelEnum.values()){
            if(methodName.equals(businessType.getDesc())){
                return businessType;
            }
        }
        return null;
    }
}